/**
 * @file transmission.h
 * @brief Header file for transmission handler
 *
 * @author Ricky Hariady (ricky.hariady@enter.web.id)
 *
 * @date 7/10/2013
 */

/*****************************/
/*        Enumeration        */
/*****************************/

/**
 * @brief Transmission protocol enumeration
 */
typedef enum
{
        T0,     ///< Using T0 Protocol
        T1,     ///< Using T1 Protocol
} t_proto;

/**
 * @brief Transmission Baudrate enumeration
 */
typedef enum
{
        B9600,  ///< Baudrate 9.600 bit/s
        B19200, ///< Baudrate 19.200 bit/s
        B38400, ///< Baudrate 38.400 bit/s
        B111600 ///< Baudrate 111.600 bit/s
} t_baudrate;

/********************************/
/*        Data Structure        */
/********************************/

/**
 * @brief structure of transmission configuration
 */
struct t_config_struct
{
        t_proto         protocol;       ///< transmission protocol to use : T0 (0) or T1 (1)
        t_baudrate      baudrate;       ///< speed (baudrate) of the transmission
};

/**************************/
/*        Variable        */
/**************************/

struct  t_config_struct tconfig;                ///< transmission configuration
struct  buffer_struct   *rx_buffer_ptr;         ///< pointer to buffer for Rx transmission
struct  buffer_struct   *tx_buffer_ptr;         ///< pointer to buffer for Tx transmission	
uint16_t                *exp_data_ptr;          ///< pointer to length of command data expected by command interpreter
bool                    *busy_flag_ptr;         ///< pointer to indication for transmission protocol if the main loop still busy

/**************************/
/*        Function        */
/**************************/

/**
 * @brief Initialize the transmission handler
 *
 * @param config The initialization structure
 * @return Result\n
 *          Success     = OK\n
 *          Not Success = Error
 */
int transInit(struct t_config_struct config);

/**
 * @brief Receive the command APDU.
 *
 * Call by IO Interrupt handler HAL_IO_ISR(), then read the data byte by HAL_IO_RxByte(). The command APDU received then placed in rx_buffer
 *
 * @return none
 */
void transRx(); 

/**
 * @brief Transmit the response APDU. 
 *
 * Transmit the response APDU from tx_buffer. Call by Response Manager.
 *
 * @return none
 */
void transTx(); 

